//
//  TabbarMenuView.m
//  ChatForHot
//
//  Created by FLY on 2018/10/9.
//  Copyright © 2018年 FLY. All rights reserved.
//

#import "TabbarMenuView.h"

@implementation TabbarMenuView

- (instancetype)init{
    
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.HOTCHATbtn1];
        
        [self addSubview:self.HOTCHATbtn2];
        [self addSubview:self.HOTCHATbtn3];
        [self addSubview:self.HOTCHATlineview];
        
        [self.HOTCHATbtn1 mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.left.bottom.equalTo(self);
            make.width.equalTo(self.HOTCHATbtn2);
            make.width.equalTo(self.HOTCHATbtn3);
        }];
        
        [self.HOTCHATbtn2 mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(self);
            make.left.equalTo(self.HOTCHATbtn1.mas_right);
        }];
        [self.HOTCHATbtn3 mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(self);
            make.left.equalTo(self.HOTCHATbtn2.mas_right);
            make.right.equalTo(self);
        }];
        
        [self.HOTCHATlineview mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.equalTo(self);
            make.height.mas_equalTo(0.5);
        }];
    }
    return self;
}
- (TabbarMenuBtn *)HOTCHATbtn1{
    if (_HOTCHATbtn1 == nil) {
        
        _HOTCHATbtn1 = [self getTabbarMenuBtnWithTag:1 Name:NSLocalizedString(@"StrN01", nil) img:@"local"];
        
    }
    return _HOTCHATbtn1;
}

- (TabbarMenuBtn *)HOTCHATbtn2{
    if (_HOTCHATbtn2 == nil) {
        
        _HOTCHATbtn2 = [self getTabbarMenuBtnWithTag:2 Name:NSLocalizedString(@"StrN02", nil) img:@"message"];
        [_HOTCHATbtn2 HOTCHATshowBadgeView];
        
    }
    return _HOTCHATbtn2;
}
- (TabbarMenuBtn *)HOTCHATbtn3{
    if (_HOTCHATbtn3 == nil) {
        
        _HOTCHATbtn3 = [self getTabbarMenuBtnWithTag:3 Name:NSLocalizedString(@"StrN03", nil) img:@"personal"];
        
    }
    return _HOTCHATbtn3;
}
- (UIView *)HOTCHATlineview{
    if (_HOTCHATlineview == nil) {
        _HOTCHATlineview = [[UIView alloc] init];
        _HOTCHATlineview.backgroundColor = HOTCHATrgb(222,222,222);
    }
    return _HOTCHATlineview;
}
//初始化
- (TabbarMenuBtn *)getTabbarMenuBtnWithTag:(NSInteger)tag Name:(NSString *)name img:(NSString *)img{
    TabbarMenuBtn *button = [[TabbarMenuBtn alloc] init];
    button.tag = tag;
    [button addTarget:self action:@selector(HOTCHATBtnClcik:) forControlEvents:(UIControlEventTouchUpInside)];
    button.menuNameStr = name;
    button.menuImgStr = img;
    
    return button;
}
- (void)HOTCHATBtnClcik:(TabbarMenuBtn *)TabbarMenuBtn{
    [self HOTCHATselectMenuAtIndex:TabbarMenuBtn.tag];
}
- (void)HOTCHATselectMenuAtIndex:(NSInteger)menuIndex{
    self.HOTCHATbtn1.selected = (menuIndex == 1);
    self.HOTCHATbtn2.selected = (menuIndex == 2);
    self.HOTCHATbtn3.selected = (menuIndex == 3);
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(HOTCHATClcikMenuIndex:)]) {
        [self.delegate HOTCHATClcikMenuIndex:(menuIndex - 1)];
    }
}
- (void)HOTCHATsetMessageBadges:(NSInteger)badges{
    
    self.HOTCHATbtn2.badgeNum = badges;
}
@end
